const joi = require('joi')

//string值只能为字符串
//alphanum 只能为a-z 0-9
//min是最小长度 max为最大长度
//requrie是必填项

//姓名,id,邮箱进行验证
const id = joi.string().required()
const name = joi.string().pattern(/^\u4e00-\u9fa5{1,5}$/).required()
const email = joi.string().pattern(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/).required()
const oldPassword = joi.string().pattern(/^(?![0-9]+$)[a-z0-9]{1,50}$/).min(6).max(12).required()
const newPassword = joi.string().pattern(/^(?![0-9]+$)[a-z0-9]{1,50}$/).min(6).max(12).required()

//暴露验证规则
exports.name_limit = {
    //body是request.body
    body: {
        id,
        name
    }
}

exports.password_limit = {
    //body是request.body
    body: {
        id,
        oldPassword,
        newPassword
    }
}


exports.email_limit = {
    //body是request.body
    body: {
        id,
        email
    }
}

